package cn.bdqn.t354.controller;

import cn.bdqn.t354.pojo.SysUser;
import cn.bdqn.t354.service.SysUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Resource
    SysUserService sysUserService;

    @RequestMapping("/login")
    public String login(String usrName, String usrPassword,
                        HttpSession session, Model model){
        SysUser sysUser = sysUserService.login(usrName, usrPassword);
        if(sysUser!=null){
            session.setAttribute("loginUser",sysUser);
            return "redirect:/main";
        }else{
            model.addAttribute("msg","用户名或者密码错误");
            return "forward:/login.jsp";
        }
    }

    @RequestMapping("/main")
    public String main(){
        return "main";
    }
}
